﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

namespace SharpDB.DAO
{
    public class MySqlDAO : DAOBase
    {
        public MySqlDAO(DbProviderFactory providerFactory, DBType dBType, string connectionString, string paramCharacter, bool checkStruct = true) 
            : base(providerFactory, dBType, connectionString, paramCharacter, checkStruct)
        {
        }

        public override void BulkCopy(DataTable data, string tableName, Dictionary<string, string> columnMappings = null, int batchSize = 200000, int bulkCopyTimeout = 60)
        {
            throw new NotImplementedException();
        }

        public override void BulkCopy(DbDataReader reader, string tableName, Dictionary<string, string> columnMappings = null, int batchSize = 200000, int bulkCopyTimeout = 60)
        {
            throw new NotImplementedException();
        }

        public override bool ValidateSql(string strSql, out string msg)
        {
            bool bResult = false;
            msg = string.Empty;
            using (DbConnection conn = CreateConn())
            {
                DbCommand cmd = CreateCmd();
                cmd.Connection = conn;
                conn.Open();
                try
                {
                    cmd.CommandText = "set noexec on;";
                    cmd.ExecuteNonQuery();

                    cmd.CommandText = strSql;
                    cmd.ExecuteNonQuery();

                    cmd.CommandText = "set noexec off;";
                    cmd.ExecuteNonQuery();
                    bResult = true;
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                    bResult = false;
                }
            }
            return bResult;
        }
    }
}
